﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Project_ScansiaPacific
{
    public partial class FrQLXuatKho : DevComponents.DotNetBar.Office2007Form
    {
        public FrQLXuatKho()
        {
            InitializeComponent();
        }
        private string find;
        public void Search()
        {
            try
            {
                Data dta = new Data();
                DataSet ds = new DataSet();
                string date_start = dateTimePicker1.Value.ToString("MM/dd/yyyy");
                string date_end = dateTimePicker2.Value.ToString("MM/dd/yyyy");
                if (rd_ChungTu.Checked == true)
                {

                    if (txt_Search.Text == "")
                    {
                        find = @"select  ChungTu, NguonCungCap, TKHaiQuan, LoaiGo, LyDoXuat, ADorKD, TieuChuan, NoiNhan, TinhTrangGo, Ngay, Serial_XK,KeHoach
                                    from Serial_XKGo";
                    }
                    else
                        find = @"select  ChungTu, NguonCungCap, TKHaiQuan, LoaiGo, LyDoXuat, ADorKD, TieuChuan, NoiNhan, TinhTrangGo, Ngay, Serial_XK,KeHoach
                                    from Serial_XKGo
                                    where ChungTu like '" + txt_Search.Text + "%'";
                }
                if (rd_NguonCungCap.Checked == true)
                {
                    if (txt_Search.Text != "")
                    {
                        find = @"select  ChungTu, NguonCungCap, TKHaiQuan, LoaiGo, LyDoXuat, ADorKD, TieuChuan, NoiNhan, TinhTrangGo, Ngay, Serial_XK,KeHoach
                                    from Serial_XKGo
                                where NguonCungCap like'" + txt_Search.Text + "%' and Ngay>='" + date_start + " 00:00:00' and Ngay<='" + date_end + " 23:59:59'";
                    }
                    if (txt_Search.Text == "")
                    {
                        find = @"select  ChungTu, NguonCungCap, TKHaiQuan, LoaiGo, LyDoXuat, ADorKD, TieuChuan, NoiNhan, TinhTrangGo, Ngay, Serial_XK,KeHoach
                                    from Serial_XKGo
                                where Ngay>='" + date_start + " 00:00:00' and Ngay<='" + date_end + " 23:59:59'";
                    }
                }
                ds = dta.dts(find);
                dataGridView1.DataSource = ds.Tables[0];
                ds.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void bt_search_Click(object sender, EventArgs e)
        {
            Search();
        }

        private void rd_ChungTu_CheckedChanged(object sender, EventArgs e)
        {
            lb.Text = "Chứng Từ";
            dateTimePicker1.Enabled = false;
            dateTimePicker2.Enabled = false;
        }

        private void rd_NguonCungCap_CheckedChanged(object sender, EventArgs e)
        {
            lb.Text = "Nguồn Cung Cấp";
            dateTimePicker1.Enabled = true;
            dateTimePicker2.Enabled = true;
        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                Process prs = new Process();
                FrEditXK FrE = new FrEditXK();
                int r = dataGridView1.CurrentCell.RowIndex;
                int index_ = int.Parse(dataGridView1.Rows[r].Cells["Serial_XK"].Value.ToString());
                string sql_select = @"select Serial_XK,ChungTu,NguonCungCap,ChieuDay,ChieuRong,ChieuDai,SoLuong,SoKhoi,GhiChu,STT,AmDo,TenNguon from dbo.XuatKhoGo
                                       where Serial_XK=" + index_;
                DataSet ds = prs.dts(sql_select);
                //MessageBox.Show(sql_select);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    FrE.Show();
                    FrE.serial(index_.ToString());
                    FrE.datagrid_load(ds);
                    //FrE.User(lb_User.Text, lb_User.Text);
                    FrE.ChungTu_Xuat(ds.Tables[0].Rows[0]["ChungTu"].ToString());
                    FrE.visible_NguonCC(index_);
                    ds.Dispose();
                }
                else
                    MessageBox.Show("Chứng từ này không có hàng hóa nào");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
       
    }
}
